home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / SPREAD.ZIP / SPREAD.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-16  |  4.8 KB  |  203 lines

  1. // ***********************************************************************
  2. //
  3. //  SPREAD.CPP Test Program
  4. //  List Viewer that displays/edits two-dimensional array
  5. //  July 19, 1994
  6. //  Adapted from TListViewer (C.Porter 70262,1047)
  7. //  Curt Thompson  CIS - 70701,2402
  8. // ***********************************************************************
  9.  
  10. #define Uses_TApplication
  11. #define Uses_TBackground
  12. #define Uses_TButton
  13. #define Uses_TInputLine
  14. #define Uses_TKeys
  15. #define Uses_TDeskTop
  16. #define Uses_TDialog
  17. #define Uses_TListBox
  18. #define Uses_TMenu
  19. #define Uses_TMenuBar
  20. #define Uses_TMenuItem
  21. #define Uses_TRect
  22. #define Uses_TScrollBar
  23. #define Uses_TStaticText
  24. #define Uses_TStatusDef
  25. #define Uses_TStatusItem
  26. #define Uses_TStatusLine
  27.  
  28. #include <tv.h>
  29. #include <stdlib.h>
  30. #include <math.h>
  31. #include "sprdview.h"
  32.  
  33. const short numColumns = 11;
  34. const short numRows = 18;
  35. static ListRec ListData[numRows][numColumns];
  36. const short numHeadRows = 2;
  37. static char *heading[numHeadRows * numColumns] = {
  38.   /* 1st row. */ "ROOT", "FACTOR", "FACTOR", "FACTOR", "FACTOR", "FACTOR", "FACTOR", "FACTOR", "FACTOR", "FACTOR", "FACTOR",
  39.   /* 2nd row. */ "NO." , "A"     , "B"     , "C"     , "D"     , "E"     , "F"     , "G"     , "H"     , "I"     , "J"
  40. };
  41. // Character width of each column.
  42. static ushort cw[numColumns] = {
  43.                   7    , 10      , 14      , 10      , 10      , 10      , 10      , 10      , 10      , 10      , 10
  44. };
  45. // Number of digits to right of decimal point to display.
  46. static ushort dp[numColumns] = {
  47.                   2    , 2       , 3       , 4       , 2       , 2       , 2       , 2       , 3       , 2       , 2
  48. };
  49.  
  50.  
  51. //  global data
  52. const cmAbout   = 100;  // User selected menu item 'About'
  53. const cmList    = 101;  // User selected menu item 'List'
  54.  
  55. //*******************************************************
  56. class TApp : public TApplication
  57. {
  58.   public:
  59.  
  60.     TApp();
  61.  
  62.     // virtual functions to be locally redefined
  63.     static TMenuBar *initMenuBar(TRect r);
  64.     void handleEvent(TEvent &event);
  65.     void idle();
  66.  
  67.     // declare new functions
  68.     void AboutDialog();
  69.     void ListDialog();
  70.  
  71. };
  72.  
  73.  
  74. //*******************************************************
  75. TApp::TApp() :
  76.    TProgInit(TApplication::initStatusLine, TApp::initMenuBar,
  77.    TApplication::initDeskTop)
  78. {
  79.  
  80.   TRect r = getExtent();
  81.   r.a.x = r.b.x - 13;
  82.   r.a.y = r.b.y - 1;
  83.  
  84. }
  85.  
  86.  
  87. //*******************************************************
  88. TMenuBar *TApp::initMenuBar(TRect r)
  89. {
  90.  
  91.   r.b.y = r.a.y + 1;
  92.   return(new TMenuBar(r, new TMenu(
  93.     *new TMenuItem("~A~bout", cmAbout, kbAltA, hcNoContext, 0,
  94.      new TMenuItem("~S~preadsheet", cmList, kbAltL, hcNoContext, 0)))));
  95.  
  96. }
  97.  
  98.  
  99. //*******************************************************
  100. void TApp::handleEvent(TEvent &event)
  101. {
  102.  
  103.    TApplication::handleEvent(event);
  104.    if (event.what == evCommand)
  105.    {
  106.       switch(event.message.command)
  107.       {
  108.      case cmAbout:       // display the about box
  109.             AboutDialog();
  110.             clearEvent(event);
  111.             break;
  112.      case cmList:        // display our list box
  113.             ListDialog();
  114.             clearEvent(event);
  115.             break;
  116.          default:
  117.             break;
  118.       }
  119.    }
  120.  
  121. }
  122.  
  123.  
  124. //*******************************************************
  125. /* AboutDialog - create modal About dialog box */
  126. void TApp::AboutDialog()
  127. {
  128.  
  129.    TDialog *pd = new TDialog(TRect(0, 0, 35, 10), "About");
  130.    if (pd)
  131.    {
  132.       pd->options |= ofCentered;
  133.       pd->insert(new TStaticText(TRect(1, 2, 34, 6),
  134.          "\003Spreadsheet Lookalike\n"
  135.          "\003Curt Thompson CIS 70701,2402\n"));
  136.       pd->insert(new TButton(TRect(13, 7, 22,9), "~O~k", cmOK, bfDefault));
  137.       (void) deskTop->execView(pd);
  138.    }
  139.    destroy(pd);
  140.  
  141. }
  142.  
  143.  
  144. //*******************************************************
  145. void TApp::ListDialog()
  146. {
  147.  
  148.   TRect r = getExtent();
  149.   r.grow(-2,-3);
  150.  
  151.   TDialog *pd = new TListViewDialog(r, "Spreadsheet Lookalike",
  152.     heading, numHeadRows, (ListRec *) &ListData[0][0], numColumns, numRows,
  153.     &cw[0], &dp[0]);
  154.  
  155.   if (validView(pd))
  156.   {
  157.  
  158.     // Allow re-sizing.
  159.     pd->flags |= wfGrow;
  160.  
  161.     // Modal...
  162.     (void) deskTop->execView(pd);
  163.  
  164.     // Distroy when done.
  165.     destroy(pd);
  166.  
  167.   }
  168.  
  169. }
  170.  
  171.  
  172. //*******************************************************
  173. void TApp::idle() {
  174.  
  175.   TProgram::idle();
  176.  
  177. }
  178.  
  179.  
  180. //************************************************************************
  181. int main(void)
  182. {
  183.  
  184.   for (int i = 0; i < numRows; i++)
  185.   {
  186.     ListData[i][0].val = (double) i;
  187.     ListData[i][0].show = True;
  188.     for (int j = 1; j < numColumns; j++)
  189.     {
  190.       ListData[i][j].val = sqrt(ListData[i][j-1].val);
  191.       if (j == 4)
  192.         ListData[i][j].show = False;
  193.       else
  194.         ListData[i][j].show = True;
  195.     }
  196.   }
  197.  
  198.   TApp myApp;
  199.   myApp.run();
  200.   return 0;
  201.  
  202. }
  203.